package com.lmc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmc.common.R;
import com.lmc.mapper.WalletsMapper;
import com.lmc.pojo.Order;
import com.lmc.pojo.User;
import com.lmc.pojo.Wallet;
import com.lmc.service.OrderService;
import com.lmc.service.UserService;
import com.lmc.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
@Transactional //涉及多表操作，添加事务
public class WalletServiceImpl extends ServiceImpl<WalletsMapper, Wallet> implements WalletService {

    //假设从浏览器中拿到用户登录的id
    String userId = "147563212344";

    /**
     * 查询用户钱包余额
     *
     * @param wallet
     * @return
     */
    @Override
    public R<Wallet> getWalletsInfo(Wallet wallet) {
        //select * from wallet where user_id = ?;
        LambdaQueryWrapper<Wallet> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotColumnName(userId), Wallet::getUserId, userId);
        Wallet walletInfo = this.getOne(lqw);
        return R.success(walletInfo);
    }

}
